<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link rel="stylesheet" type="text/css" href="../resource/css/base.css">
		<script type="text/javascript" src="../resource/js/prototype.js"></script>
		<script type="text/javascript" src="../resource/js/My97DatePicker/WdatePicker.js"></script>
		<s:actionmessage/>
		<style type="text/css">
			ul,li,p{margin:0;padding:0;}
			ul,li{list-style:none;zoom:1;}
			a{color:#00c;}
			#nav{border-bottom:1px solid #c7e8bc;margin:5px 0;padding:0 0 0 10px;}
			#navTab li{float:left;width:73px;height:26px;overflow:hidden;margin-right:6px;font:bold 14px/26px arial;text-align:center;background:url(../resource/image/bg_popbtn.gif) no-repeat -78px -185px;position:relative;top:1px;}
			#navTab li.act a{text-decoration:none;}
			#navTab li a:link,li a:visited{width:100%;padding-top:2px;color:#1d7a00;display:block;}
			#navTab li.act{outline:none;background-position:0 -185px;}
			#main{padding:0 10px;margin-bottom:12px;background:#fff;margin:0 auto;text-align:center;}
			.clear{height:0;overflow:hidden;font-size:0;line-height:0;margin:0;padding:0;clear:both;}
		</style>
		<script type="text/javascript">
			function $(name){return document.getElementsByName(name);}
			function $$(name){return document.getElementById(name);}
			function changeTab(idx){
				var lis = document.getElementsByTagName("li");
				for (var i = 0; i < lis.length; i++){
					lis[i].className = "";
					document.getElementById("div_" + i).style.display = "none";
				}
				lis[idx].className = "act";
				document.getElementById("div_" + idx).style.display = "block";
			}
			
			function doSelect(idx){
				if (idx == 0){ //选择自有车辆及驾驶员
					var data = {};
					var drivers = [];
					var driverIds = [];
					var driverNames = [];
					//临时变量
					var i;
					var _trucks = $("truckid");
					for (i = 0; i < _trucks.length; i++){
						if (_trucks[i].checked){
							data.truckId = _trucks[i].value;
							break;
						}
					}
					if (i == _trucks.length){
						alert("请选择车辆.");
						return false;
					}
					var _drivers = $("driverid");
					for (var i = 0; i < _drivers.length; i++){
						if (_drivers[i].checked){
							var driver = {"driverId":_drivers[i].value, "name":_drivers[i].parentNode.innerText};
							drivers[drivers.length] = driver;
							driverIds[driverIds.length] = _drivers[i].value;
							driverNames[driverNames.length] = _drivers[i].parentNode.innerText.replace(/(^\s*)|(\s*$)/g, "");
						}
					}
					if(drivers.length == 0){
						alert("请选择驾驶员.");
						return false;
					}
					data.drivers = drivers;
					data.driverIds = driverIds;
					data.driverNames = driverNames;
					parent.setTruck(data);
					parent.ClosePop();
				}
				if(idx == 1){//输入外来车辆
					var data = {};
					//数据验证
					if($$("borrowedTruckId").value==""){
						alert("请填写车牌号.");
						return false;
					}
					if($$("ownName").value==""){
						alert("请填写车主姓名.");
						return false;
					}
					if($$("unitFee").value==""){
						alert("请填写每吨租费.");
						return false;
					}
					if($$("entryTime").value==""){
						alert("请填写借入日期.");
						return false;
					}
					var pattern = /^[0-9]+(\.[0-9]{1,2}){0,1}$/;
					if (!pattern.test($$("unitFee").value)){
						alert("每吨租费格式有误.请填写数字");
						return false;
					}
					
					data.truckId = $$("borrowedTruckId").value;
					data.ownName = $$("ownName").value;
					data.unitFee = $$("unitFee").value;
					data.entryTime = $$("entryTime").value;
					data.note = $$("note").value;
					parent.setTruck(data);
					parent.ClosePop();
				}
			}
		</script>
	</head>
	<body  oncontextmenu="return false;" leftmargin="3" topmargin="2" style="overflow: hidden;">
		<div id="main">
	        <div id="normalBody">
		    	<div id="nav">
		            <ul id="navTab">
		                <li class="act"><a href="#" hidefocus="true" onclick="changeTab('0');">派车选择</a></li>
		                <li><a href="#" hidefocus="true" onclick="changeTab('1');">借车录入</a></li>
		            </ul>
		            <p class="clear"></p>
		        </div>
			</div>
			<div style="width:100%; height:93%; margin:5px;">
				<div id="div_0" align="center">
					<fieldset style="text-align:left; float:left; width:49.5%;">
						<legend>车辆列表</legend>
						<div style="margin:5px; height:290px; overflow: auto;">
							<s:iterator value="trucks" status="vo">
								<span style="text-align: left; width:45%;">
									<input name="truckid" type="radio" value="<s:property value="truckId"/>"/>
									<s:property value="truckId"/></span>
								<s:if test="#vo.count % 2 == 0">
									<br>
								</s:if>
							</s:iterator>
						</div>
					</fieldset>
					<fieldset style="text-align:left; float:left; width:49.5%; margin-left: 6px;">
						<legend>驾驶员列表</legend>
						<div style="margin:5px; height:290px; overflow: auto;">
							<s:iterator value="drivers" status="vo">
								<span style="text-align: left; width:45%;">
									<input name="driverid" type="checkbox" value="<s:property value="driverId"/>"/>
									<s:property value="name"/></span>
								<s:if test="#vo.count % 2 == 0">
									<br>
								</s:if>
							</s:iterator>
						</div>
					</fieldset>
					<div style="margin-top: 5px;">
						<a href="#" onclick="return doSelect(0);" class="coolbg" style="width: 50px; height: 20px;">&nbsp;确&nbsp;定</a>&nbsp;&nbsp;
						<a href="#" onclick="return parent.ClosePop();" class="coolbg" style="width: 50px; height: 20px;">&nbsp;取&nbsp;消</a>&nbsp;&nbsp;
					</div>
				</div>
				<div id="div_1" style="display: none;">
					<fieldset>
						<legend>借车信息</legend>
						<form id="form1">
							<table class="edittb" cellpadding="2" cellspacing="1" style="margin: 3px;">
								<tr>
									<td class="coln"><SPAN style="color: red">*</SPAN> 车 牌 号</td>
									<td class="colv">
										<s:textfield id="borrowedTruckId" name="borrowedTruckId"/>
									</td>
									<td class="coln"><SPAN style="color: red">*</SPAN> 车主姓名</td>
									<td class="colv">
										<s:textfield id="ownName" name="ownName"/>
									</td>
								</tr>
								<tr>
									<td class="coln"><SPAN style="color: red">*</SPAN> 每吨租费</td>
									<td class="colv">
										<s:textfield id="unitFee" name="unitFee"/>
									</td>
									<td class="coln"><SPAN style="color: red">*</SPAN> 借入时间</td>
									<td class="colv">
										<s:textfield id="entryTime" name="entryTime" onclick="WdatePicker();" cssClass="Wdate" />
									</td>
								</tr>
								<tr>
									<td class="coln">备&nbsp;&nbsp;&nbsp;&nbsp;注</td>
									<td class="colv" colspan="3">
										<s:textarea id="note" name="note" cssStyle="width:92.5%;"></s:textarea>
									</td>
								</tr>
							</table>
							<div style="margin-top: 5px;">
								<a href="#" onclick="return doSelect(1);" class="coolbg" style="width: 50px; height: 20px;">&nbsp;确&nbsp;定</a>&nbsp;&nbsp;
								<a href="#" onclick="$$('form1').reset();" class="coolbg" style="width: 50px; height: 20px;">&nbsp;重&nbsp;置</a>&nbsp;&nbsp;
								<a href="#" onclick="return parent.ClosePop();" class="coolbg" style="width: 50px; height: 20px;">&nbsp;取&nbsp;消</a>&nbsp;&nbsp;
							</div>
						</form>
					</fieldset>
				</div>
			</div>
		</div>
	</body>
</html>
